if (!jsx3.lang.Class.forName("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistLinkman")) {

    /**
     * Define the <code>name of class</code> class.
     * This class inherit from <code>jsx3.gui.Block<code> GUI class.
     */	
    jsx3.Class.defineClass("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistLinkman", ux.megatron.gui.WizardPanel, null, function(objRoot){
        objRoot.prototype.btnAdd = null; //add button
        objRoot.prototype.btnEdit = null; //edit button
        objRoot.prototype.btnDelete = null; //delete button
        objRoot.prototype.matrix = null;//matrix
        objRoot.prototype.canEdit = false;//whether the record can edit
        objRoot.prototype.blkExpend = null;//the panel which contain the buttons "save&cancel"
        objRoot.prototype.initRecords=null;//save the content befor edit
        objRoot.prototype.wizard=null;
		objRoot.prototype.message=null;
        /*
         * This method will be called after UI file has deserialized.
         */
        objRoot.prototype.onAfterDeserialize = function(){
        	

			
        }
        objRoot.prototype.ruleChecked = function(){

        	if (this.matrix.getCheckedNodes().size()>0)
			{
				this.btnDelete.setEnabled(jsx3.gui.Form.STATEENABLED, true);
			}
			else
			{
				this.btnDelete.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
			}
		}
		objRoot.prototype.onAdd = function(){
			//user click add button 
			//enter the add mode
			this.canEdit=true;
			//save the records for revert
			this.initRecords=this.matrix.getXML().cloneDocument();
			//insert a new record
			var record=this.matrix.insertRecord({jsxid:jsx3.xml.CDF.getKey(),jsxIsModify:"true",jsxIsNew:"true",jsxname:""},null,false);
			this.matrix.repaintData();
			//show save&canel button
			this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true); 
		}
		//user modify the data
		objRoot.prototype.onChange=function(column,recordId)
		{
			if (column.getName()=="LinkmanType")
			{
				var node=this.matrix.getRecordNode(recordId);
				var selection=this.getDescendantOfName("selLinkmanType");
				node.setAttribute("jsxtypename",selection.getText());
				node.setAttribute("jsxtype",selection.getValue());
			}
			this.matrix.getRecordNode(recordId).setAttribute("jsxIsModify","true");
		}

		objRoot.prototype.onEdit = function(){
			if (this.canEdit == false) {//if current not eidt mode, then change the statue to edit mode
				this.canEdit = true;
				//save the records for revert
				this.initRecords=this.matrix.getXML().cloneDocument();
				this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
			}
		}
		objRoot.prototype.callDeleteRecord=function(objEvent)
		{//call service to delete the selected record
			objEvent.doClose();//close the confirm window
			if (this.canEdit) {
			//cancel the edit
			//revert the record
			
			}
		}
		objRoot.prototype.onSave = function(){
			//here to save
			//to clear the empty record
			var nodes=this.matrix.getXML().selectNodes("record[@jsxname='']");

			var i;
			for(i=0;i<nodes.size();i++)
			{
				this.matrix.deleteRecord(nodes.get(i).getAttribute("jsxid"));
			}
			this.matrix.repaintData();
			//out the edit mode
			this.canEdit=false;
			//hidde the button save&cancel
			this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
		}
		objRoot.prototype.onLinkmanCancel = function(){
			//here to cancel
			var server=ux.megatron.Main.getServer();
			var me=this;
			//rever the data
			me.matrix.getXML().loadXML(this.initRecords.toString());
			me.matrix.repaintData();
			//hidde the button save&cancel
			me.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
			me.canEdit=false;
			//out the edit mode
			
		}
		objRoot.prototype.getCanEdit = function(){
			return this.canEdit;
		}
		objRoot.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
	
			//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
			this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
		};

		objRoot.prototype.initialize = function(msg) {
			//this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
			var me=this;
            this.btnAdd = this.getDescendantOfName("btn_Linkman_add");
            this.btnEdit = this.getDescendantOfName("btn_Linkman_edit");
            this.btnDelete = this.getDescendantOfName("btn_Linkman_delete");
            this.blkExpend=this.getDescendantOfName("blkExpend");
			this.matrix=this.getDescendantOfName("mtxEditLinkman");
			this.matrix.subscribe(ux.cdb.admin.gui.Matrix.EVENT_CHECKALL, me, me.ruleChecked);
			this.wizard = this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard");
			//get cache of CONTACT_PERSON_TYPE
			//ux.cdb.admin.CommonCache.loadCache(['CONTACT_PERSON_TYPE'], me,me.cacheLoaded);
			this.cacheLoaded();
			
		}
		/**
		 * call back function when cache loaded
		 */
		objRoot.prototype.cacheLoaded=function()
		{
			var me=this;
			var cache = ux.cdb.admin.CommonCache.getInstance();
					this.getDescendantOfName("selLinkmanType").setSourceXML(cache.getCache('CommonCache_CONTACT_PERSON_TYPE'));
			//get the data from the server
			if (this.wizard.isEdit) {//current mode is edit
				ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "getContactPersonListByCondition", [this.wizard.orgId], me, me.loadLinkman);
			}
			this.matrix.focus();
		}
		
		/**
		 * receive the data from server
		 */
		objRoot.prototype.loadLinkman=function(obj)
		{
			//alert(ux.megatron.util.JSON.JSONtoString(objEvent));
			var commonCache = ux.cdb.admin.CommonCache.getInstance();
			var cache=jsx3.xml.CDF.Document.newDocument();
			var objEvent=obj.content.data;
			this.wizard.linkmanObj=objEvent;//because the UCC need the return object must had all the field that send from UCC, so save it,and merge with which user edit,and send back
			var cacheRecord=(commonCache.getCache('CommonCache_CONTACT_PERSON_TYPE'));
			var record;
			var typeRecord;
			console.log(ux.megatron.util.JSON.JSONtoString(obj));
			
	
			for(var i=0;i<objEvent.length;i++)
			{
				
				typeRecord=cacheRecord.selectSingleNode("//record[@jsxid = '" + objEvent[i].contactPersonTypeCode + "']");
				record={
						jsxIsModify:"false",//是否修改过
						jsxIsNew:"false",//是否新纪录
						jsxid:objEvent[i].contactPersonId,
						jsxtype:objEvent[i].contactPersonTypeCode,
						jsxtypename:typeRecord.getAttribute("jsxtext"),
						jsxname:objEvent[i].contactPersonName,
						jsxtelephone:objEvent[i].contactPersonFixPhone,
						jsxcellphone:objEvent[i].contactPersonMobNum,
						jsxemail:objEvent[i].contactPersonEmail
						};

				cache.insertRecord(record);			
			}
            //ux.megatron.Main.loadResource("ux/cdb/admin/mechanism/cooOrg/testdata/CooOrg_testdata.xml", "ux.cdb.admin", "cchCooOrgList", "xml");
			ux.megatron.Main.getServer().getCache().setDocument("cchCooOrgEditLinkman",cache);
			this.matrix.repaint();
		}
		objRoot.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			//user click next save likeman
			//this.onSave();
			if (this.doValidate()!=true)
			{
				this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(this.message);
				return "NONE";
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").clearWarnMessage();
			return null; // return "NONE" to not next panels
		}
		
		objRoot.prototype.doValidate=function()
		{
			//alert(this.matrix.getChildNodes());
			var nodes=this.matrix.getXML().getChildNodes();

			var phoneValidator=ux.megatron.util.ValidationManager.getValidator("Phone");
			var mobileValidator=ux.megatron.util.ValidationManager.getValidator("Mobile");
			var emailValidator=ux.megatron.util.ValidationManager.getValidator("Email");


			
			for(var i=0;i<nodes.size();i++)
			{
				
				this.message=phoneValidator(nodes.get(i).getAttribute("jsxtelephone"));
				if (this.message!=null)
				{	
					return false;
				}
				
				this.message=mobileValidator(nodes.get(i).getAttribute("jsxcellphone"));
				if (this.message!==null)	
				{	
					return false;
				}
				
				this.message=emailValidator(nodes.get(i).getAttribute("jsxemail"));
				if (this.message!=null)	
				{
					return false;
				}
			}
			return true;
		}
		
		//call back message for test
		objRoot.prototype.backMessage=function(objEvent)
		{
		}
		//when user click delete
		objRoot.prototype.onDelete=function()
		{
			var server=ux.megatron.Main.getServer();
			var me=this;
            /*
			ux.megatron.Dialog.confirm(
				server.getDynamicProperty("@cdb@Mechanism@CooOrg@AlertTitle"), 
				server.getDynamicProperty("@cdb@Mechanism@CooOrg@QueryDelete"), 
				function(dialog)
				{//do delete
					var nodes = me.matrix.getCheckedNodes();
					var data=new Array();
                    for(var i = 0; i < nodes.size(); i++) {
                       data.push({
							contactPersonId: record.get(i).getAttribute("jsxid"),//联系人ID
							contactPersonTypeCode: record.get(i).getAttribute("jsxtype"),//联系人类型
							contactPersonName: record.get(i).getAttribute("jsxname"),//联系人姓名
							contactPersonFixPhone: record.get(i).getAttribute("jsxtelephone"),//固定电话
							contactPersonMobNum: record.get(i).getAttribute("jsxcellphone"),//移动电话
							contactPersonEmail: record.get(i).getAttribute("jsxemail") //电子邮件	
						});
                    }
					ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "removeContactPerson", [data], me, me.recordDeleted);
                    dialog.doClose();
				},
				null
			);*/
			var nodes = me.matrix.getCheckedNodes();
			var data=new Array();
            for(var i = 0; i < nodes.size(); i++) {
				if (nodes.get(i).getAttribute("jsxIsNew") != "true") 
				{
					//if the record is not the new record,then delete the record
					data.push(nodes.get(i).getAttribute("jsxid"));//联系人ID
				}
            }

			ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "removeContactPersons", [data], me, me.recordDeleted);

		}
		//call back record deleted
		objRoot.prototype.recordDeleted=function(objEvent)
		{ //get data from server
		    var me=this;
			//ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "getContactPersonListByCondition",[""], me, me.loadLinkman);
			var nodes = me.matrix.getCheckedNodes();
			var data=new Array();
            for(var i = 0; i < nodes.size(); i++) {
				//if the record is not the new record,then delete the record
				me.matrix.deleteRecord(nodes.get(i).getAttribute("jsxid"));//remove record from matrix
            }

			this.ruleChecked();
		}
		/**
		 *  likeman type selected
		 */
		objRoot.prototype.onLinkmanTypeSelected=function(selection)
		{

		}
		
		objRoot.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			//validate
			if (this.doValidate()!=true)
			{
				this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(this.message);
				return "NONE";
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").clearWarnMessage();
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not last status
		}

		objRoot.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard").onClose();
			return null; // return "NONE" to not advance panels
		}
		objRoot.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			//validate
			if (this.doValidate()!=true)
			{
				this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(this.message);
				return "NONE";
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").clearWarnMessage();
			var saver=this.wizard.getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistSummary")[0];
		
			saver.saveSummeryInfo();
		
			return null; // return "NONE" to not last status
		}
		objRoot.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
			if(!this.getChild(0)) {
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/builder/step3/ui/CooOrgLoanAssistLinkmanContent.xml", me, me.initialize);
			}
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
			return null; // return "NONE" to not advance panels
		}
    });
}
